define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yalimedia/question/log/index' + location.search,
                    multi_url: 'yalimedia/question/log/multi',
                    // edit_url: 'yalimedia/question/log/edit',
                    // del_url: 'yalimedia/question/log/del',
                    import_url: 'yalimedia/question/log/import',
                    table: 'yalimedia_question_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'nickname', title: __('NickName')},
                        {field: 'course_name', title: __('Course_name')},
                        {field: 'right_count', title: __('Right_count')},
                        {field: 'error_count', title: __('Error_count')},
                        // {field: 'empty_count', title: __('Empty_count')},
                        {field: 'status', title: __('Status'), formatter: function (value) {
                            if(value == 1){
                                return '<span class="text-warning">进行中</span>';
                            }else if(value == 2){
                                return '<span class="text-info">已完成</span>';
                            }
                            return '';
                        }, searchList: {1: __('进行中'), 2: __('已完成')}},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [{
                                    name: 'allocation',
                                    title: __('详情'),
                                    text:'详情',
                                    extend:'data-area=["80%","80%"]',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    icon: 'fa fa-bars',
                                    url: 'yalimedia/question/detail/list'
                            }],
                            formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
